{% extends "base.html" %}

{% block title %}首页 - 个人博客系统{% endblock %}

{% block content %}
<div class="row">
    <div class="col-md-8 offset-md-2">
        <h1 class="mb-4">最新文章</h1>
        
        {% if posts %}
            {% for post in posts %}
                <div class="card mb-4">
                    <div class="card-body">
                        <h5 class="card-title">
                            <a href="{{ url_for('post', post_id=post.id) }}" class="text-decoration-none">
                                {{ post.title }}
                            </a>
                        </h5>
                        <p class="post-meta mb-2">
                            <i class="fas fa-user"></i> {{ post.author.username }}
                            <i class="fas fa-calendar ms-3"></i> {{ post.date_posted.strftime('%Y-%m-%d %H:%M') }}
                        </p>
                        <p class="card-text">{{ post.content[:200] }}{% if post.content|length > 200 %}...{% endif %}</p>
                        <a href="{{ url_for('post', post_id=post.id) }}" class="btn btn-primary btn-sm">阅读全文</a>
                    </div>
                </div>
            {% endfor %}
        {% else %}
            <div class="text-center">
                <i class="fas fa-blog fa-5x text-muted mb-3"></i>
                <h3 class="text-muted">暂无文章</h3>
                {% if current_user.is_authenticated %}
                    <p class="text-muted">快来发布第一篇文章吧！</p>
                    <a href="{{ url_for('create_post') }}" class="btn btn-primary">
                        <i class="fas fa-plus"></i> 写文章
                    </a>
                {% else %}
                    <p class="text-muted">登录后发布你的第一篇文章！</p>
                    <a href="{{ url_for('login') }}" class="btn btn-primary">
                        <i class="fas fa-sign-in-alt"></i> 登录
                    </a>
                {% endif %}
            </div>
        {% endif %}
    </div>
</div>
{% endblock %}
